﻿using System.Collections.Generic;
using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.Logic;

namespace IQIGame.Onigao.GamePlay
{
    public class SkillEffectivePackageResponse : IReusableClassWithFree, ISerializeCustomPOD
    {
        public List<Response> packageResps = new List<Response>();

        public void Add(int nTarget, SkillEffectiveResponse rSkillResp)
        {
            var rResp = ClassPool.Get<Response>();
            rResp.target = nTarget;
            rResp.resp = rSkillResp;
            this.packageResps.Add(rResp);
        }

        public uint MaxStore => 2;

        public void OnReset()
        {
            // 内部的packageresp在执行完之后已经释放过了
            this.packageResps.Clear();
        }

        public void Free()
        {
            ClassPool.Put(this);
        }

        public void Serialize(SOutputStream _buf)
        {
            SerializeCustomPODUtil.SerializeList(_buf, this.packageResps);
        }

        public void DeSerialize(SInputStream _buf)
        {
            SerializeCustomPODUtil.DeSerializeList(_buf, ref this.packageResps);
        }

        public class Response : IReusableClassWithFree, ISerializeCustomPOD
        {
            public int target;
            public SkillEffectiveResponse resp;

            public void Serialize(SOutputStream _buf)
            {
                _buf.Write_int(this.target);
                SerializeCustomPODUtil.SerializeObject(_buf, this.resp);
            }

            public void DeSerialize(SInputStream _buf)
            {
                this.target = _buf.Read_int();
                SerializeCustomPODUtil.DeSerializeObject(_buf, ref this.resp);
            }

            public uint MaxStore => 5;

            public void OnReset()
            {
                this.resp.Free();
            }

            public void Free()
            {
                ClassPool.Put(this);
            }
        }
    }
}